#! /bin/bash
re="y"
echo “开始磁盘扩容”
# echo $lvm_name
while [ "$re" == "y" ]
do
    lvs
    read -p "(依次输入需要扩容的lvm系统和添加的大小G:)"  lvm_name size_add
    # 根据lvm找到对于的vg
    vg_name=$(lvs|grep "$lvm_name "|awk '{print $2}')
    echo $vg_name
    if [ "$vg_name" == "" ];
    then
        echo "没找到这个逻辑卷，请核对后重新输入"
        continue
    fi
    # echo $vg_name
    # 查看vg剩余容量，输出，并对比
    free_size=$(vgs --units G|grep "$vg_name "|awk '{print $7}')
    echo $vg_name"剩余"$free_size
    free_size=$(echo $free_size | sed 's/[a-zA-Z]//' | awk -F '.' '{print $1}')
    echo $free_size $size_add
    if [ $size_add -le $free_size ];
    then
        lvextend -L +$size_add'G' /dev/$vg_name/$lvm_name
    else
        echo "vg剩余空间不足"
        continue
    fi
    re="n"
done
lvs